package com.neusoft.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.neusoft.bean.Userinfo;
import com.neusoft.service.IUserService;
import com.neusoft.service.UserServiceImpl;
import com.neusoft.utils.Md5Utils;

/**
 * Servlet implementation class UpdatepassServlet
 */
@WebServlet("/updatepass.do")
public class UpdatepassServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdatepassServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String nowpass = 	request.getParameter("nowpass");
		String pass= 	 request.getParameter("pass");
		String repass =	 request.getParameter("repass");
		Userinfo user = (Userinfo) request.getSession().getAttribute("login_user");
		int id = user.getId();
			System.out.println(nowpass+pass+repass);
			
			IUserService is = new UserServiceImpl();
			if( !is.findpass(id,Md5Utils.md5(nowpass))){
				
				if(pass.equals(repass)){
					
					is.updatepass(id,Md5Utils.md5(pass));
					response.sendRedirect(request.getServletContext().getContextPath()+"/jsp/user/login.jsp");
				}
			}
			
			
	}

}
